< previous page page_315 next page >

Page 315
Positioning Child Forms
Run the program and display the Employee Information form. Notice that it appears in just one spot on the MDI. If you want to automatically position this form, you can set the Top and Left properties of the Employee Information form. However, these positions are in relation to the MDI forms client area (the area of an MDI form just below the menu and right above the bottom of the form). Therefore, the coordinates 0,0 relate the position immediately under the MDI forms menu.
Centering Forms
Sometimes you may want to center child forms within the parent form. Although theres a StartUpPosition property on the forms, when you set the MDIChild property to True, this property cannot be set to anything other than Manual. This means you need to write code to position the form. Heres some code that centers an MDI child form within the main form:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Sub ChildFormCenter(oForm As Form)
   With oForm
      .Move (frmMain.ScaleWidth / 2) - (.Width / 2), _
            (frmMain.ScaleHeight / 2) - (.Height / 2)
   End With
End Sub
This code uses the frmMain forms ScaleWidth and ScaleHeight properties as the base for where to move the form. The Scale properties provide the inside dimensions of the MDI form. The inside dimensions are from the bottom of the menu area of the form to the bottom of the form, minus any border and controls that are aligned to the bottom of the formin other words, the MDI client area. Calling the ChildFormCenter() procedure from the Form_Load() event of the Employee Information form will center this form within the parent form.
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub Form_Load()
   Call ChildFormCenter(Me)
End Sub
9f31265bb40b592b1929e18a47ab28e5.gif
NOTE
MDI child forms cannot have their
StartUpPosition properties set to anything other than 0-Manual.

 
< previous page page_315 next page >

If you like this book, buy it!